package com.alkaid.anime.controller;

import com.alkaid.anime.service.AnimeService;
import com.alkaid.commons.controller.BaseController;
import com.alkaid.commons.entity.Anime;
import com.alkaid.commons.entity.AnimePageEntity;
import com.alkaid.commons.param.anime.AnimePlay;
import com.alkaid.commons.utils.JsonResult;
import com.github.pagehelper.PageInfo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Kylin
 */
@RestController
@RequestMapping("api/anime")
public class AnimeController extends BaseController {

    private final AnimeService animeService;

    public AnimeController(AnimeService animeService) {
        this.animeService = animeService;
    }

    /**
     * 热度排行
     *
     * @param num the num
     * @return the hot list
     */
    @GetMapping("/hot_list/{num}")
    public JsonResult<List<Anime>> getHotList(@PathVariable Integer num) {
        List<Anime> lists = animeService.getHotList(num);
        return new JsonResult<>(200, lists, "success");
    }

    @PostMapping("/all")
    public JsonResult<PageInfo<Anime>> getAll(@Validated AnimePageEntity page) {
        PageInfo<Anime> pageInfo = animeService.getAll(page);
        return new JsonResult<>(200, pageInfo, "success");
    }

    /**
     * 播放量排行
     *
     * @param num the num
     * @return the count list
     */
    @GetMapping("/count_list/{num}")
    public JsonResult<List<Anime>> getCountList(@PathVariable int num) {
        List<Anime> lists = animeService.getCountList(num);
        return new JsonResult<>(200, lists, "success");
    }

    @GetMapping("/play/ss/{id}")
    public JsonResult<AnimePlay> getAnimePlayByAnimeId(@PathVariable Integer id) {
        AnimePlay animePlay = animeService.getAnimePlay(id);
        return new JsonResult<>(200, animePlay, "success");
    }
}
